#pragma once

#include <iostream>
#include <rfl.hpp>
#include <rfl/toml.hpp>
#include <QFile>
#include <QByteArray>
#include "base/xlog.h"

struct Driver2SocksConfig {
    bool use_wintun;
    bool enable_ipv6;
    std::string socks5_server_ip;
    uint16_t socks5_server_port;
    std::vector<std::string> app_names;
    // Driver2SocksConfig():
    //     enable_ipv6(false),
    //     socks5_server_ip("127.0.0.1"),
    //     socks5_server_port(7890)
    // {}
    bool readFromFile(const QString& file_path)
    {
        std::unique_ptr<QFile,void(*)(QFile*)> file(new QFile(file_path),[](QFile* f){f->close();delete f;});
        if (!file->open(QIODevice::ReadOnly)) {
            SERROR("cfg.toml open error:{}.",file->errorString());
            return false;
        }
        std::string buff;
        buff.resize(file->size());
        file->read(buff.data(),file->size());
        auto result = rfl::toml::read<Driver2SocksConfig>(buff);
        if (result) {
            *this = result.value();
            return true;
        } else {
            SERROR("cfg.toml read error:{}.",result.error()->what());
        }
        return false;
    }
    bool writeToFile()
    {

    }
};

